<template>
  <div class="musicList">
    <div class="musicTop">
      <div class="title">发现好歌单</div>
      <div class="more">查看更多</div>
    </div>
    <div class="musicContent">
      <van-swipe
        :loop="false"
        :width="150"
        class="my-swpie"
        :show-indicators="false"
      >
        <van-swipe-item v-for="item in musicList" :key="item">
            <router-link :to="{path:'/ItemMusic',query:{id:item.id}}">
          <img :src="item.picUrl" alt="" />
          <span class="playCount">
            <svg class="icon" aria-hidden="true">
              <use xlink:href="#icon-bofang"></use>
            </svg>
            {{ changeCount(item.playCount) }}
          </span>
          <span class="name">{{ item.name }}</span>
           </router-link>
        </van-swipe-item>
       
      </van-swipe>
    </div>
  </div>
</template>

<script>
import { getMusicList } from "@/request/api/home.js";
export default {
  data() {
    return {
      musicList: [],
    };
  },
  methods: {
    async getGedan() {
      let res = await getMusicList();
      console.log(res);
      this.musicList = res.data.result;
    },
    changeCount: function (num) {
      if (num > 100000000) {
        return (num / 100000000).toFixed(1) + "亿";
      } else if (num >= 10000) {
        return (num / 10000).toFixed(1) + "万";
      }
    },
  },
  mounted() {
    this.getGedan();
  },
};
</script>

<style lang="less" scoped>
.musicList {
  width: 100%;
  height: 5rem;
  padding: 0.2rem;
  .musicTop {
    display: flex;
    width: 100%;
    justify-content: space-between;
    align-items: center;
    .title {
      margin-left: 0.2rem;
      font-weight: 900;
    }
    .more {
      border: 1px solid #ccc;
      border-radius: 0.4rem;
      padding: 0.1rem;
      font-size: 0.24rem;
      margin-bottom: 0.2rem;
      // line-height: 0.6rem;
    }
  }
}
.musicContent {
  width: 100%;
  height: 4rem;
  .my-swpie {
    height: 100%;
    .van-swipe-item {
        position: relative;
        margin-left: .2rem;

        .playCount{
            // color: #fff;
            position: absolute;
            display: flex;
            align-items: center;
            right: .2rem;
            top: .1rem;
            .icon{
                width: .4rem;
                // color: #fff;
                fill:#fff
            }
        }
      img {
        width: 100%;
        height: 3rem;
        border-radius: .2rem;
      }
    }
  }
}
</style>

